<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-07-12 10:56:47
 * @LastEditors: charles
 * @LastEditTime: 2021-08-01 14:08:29
-->
<template>
  <div class="projects">
      <div class="wrapper">
        <div class="title">{{categoryName}}</div>
        <div
          @click="articleHandler(article.id)"
          class="project"
          v-for="article in articles"
          :key="article.id"
        >
          <div class="left">
            <img width="100%" :src="article.cover" alt="" />
          </div>
          <div class="right">
            <div class="name">{{ article.title }}</div>
            <div class="time">
              {{ article.publishTime | fmtDate }}
            </div>
            <div class="content">阅读次数：{{article.readTimes}}点赞次数：{{article.thumpUp}}</div>
          </div>
        </div>
      </div>
    </div>
</template>
<script>
import {get} from '../utils/request'
export default {
  data(){
    return{
      //向后台传递的参数
      list:{
        page:1,
        pageSize:10,
        categoryId:this.$route.query.categoryId,
      },
      categoryName:this.$route.query.categoryName,
      articles:[]
    }
  },
  //侦听器
  watch: {
    "$route.query.categoryId":function () {
      this.list.categoryId = this.$route.query.categoryId
      this.categoryName = this.$route.query.categoryName
      this.findArticleById()
    }
  },
  methods: {
    //通过categoryId查询所有资讯信息
    findArticleById(){
      //数据交互
      get('/index/article/pageQuery',this.list).then((res)=>{
        // console.log(res);
        if(res.status == 200){
          this.articles = res.data.list
        }else{
          this.$message({
            type:'error',
            message:res.message
          })
        }
      })
    },
    //跳转到风采详情页面
    articleHandler(id){
      this.$router.push({path:'/article',query:{id:id}})
    }

  },
  created() {
    this.findArticleById()
  },
}

</script>

<style lang="scss" scoped>
.projects {
  .wrapper {
    // width:1240px;
    // height:500px;
    // background-color: teal;
    cursor: pointer;
    .title {
      font-size:20px;
      line-height: 4em;
      border-bottom: 1px solid #f4f4f4;
    }
    .project {
      display: flex;
      padding: 1em 0;
      border-bottom: 1px solid #f4f4f4;
      .left {
        width:300px;
        height:200px;
        background-color: #f4f4f4;
        border-radius: 5px;
        overflow: hidden;
      }
      .right {
        flex: 1;
        // background-color: teal;
        padding: 0 2em;
        .name {
          font-weight: 500;
          font-size:15px;
        }
        .time {
          margin: 1em 0;
        }
        .content {
          line-height: 2em;
        }
      }
    }
  }
  
}
</style>